package com.empire.module.spider.service.lotteryfootballgamezucaisfc;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.spider.controller.app.lotteryfootballgamezucaisfc.vo.*;
import com.empire.module.spider.dal.dataobject.lotteryfootballgamezucaisfc.LotteryFootballGameZucaiSfcDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.spider.dal.mysql.lotteryfootballgamezucaisfc.LotteryFootballGameZucaiSfcMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.spider.enums.ErrorCodeConstants.*;

/**
 * 足彩胜负彩、任九比赛 Service 实现类
 *
 * @author 无敌
 */
@Service
@Validated
public class LotteryFootballGameZucaiSfcServiceImpl implements LotteryFootballGameZucaiSfcService {

    @Resource
    private LotteryFootballGameZucaiSfcMapper lotteryFootballGameZucaiSfcMapper;

    @Override
    public String createLotteryFootballGameZucaiSfc(AppLotteryFootballGameZucaiSfcSaveReqVO createReqVO) {
        // 插入
        LotteryFootballGameZucaiSfcDO lotteryFootballGameZucaiSfc = BeanUtils.toBean(createReqVO, LotteryFootballGameZucaiSfcDO.class);
        lotteryFootballGameZucaiSfcMapper.insert(lotteryFootballGameZucaiSfc);
        // 返回
        return lotteryFootballGameZucaiSfc.getFid();
    }

    @Override
    public void updateLotteryFootballGameZucaiSfc(AppLotteryFootballGameZucaiSfcSaveReqVO updateReqVO) {
        // 校验存在
        validateLotteryFootballGameZucaiSfcExists(updateReqVO.getFid());
        // 更新
        LotteryFootballGameZucaiSfcDO updateObj = BeanUtils.toBean(updateReqVO, LotteryFootballGameZucaiSfcDO.class);
        lotteryFootballGameZucaiSfcMapper.updateById(updateObj);
    }

    @Override
    public void deleteLotteryFootballGameZucaiSfc(String id) {
        // 校验存在
        validateLotteryFootballGameZucaiSfcExists(id);
        // 删除
        lotteryFootballGameZucaiSfcMapper.deleteById(id);
    }

    private void validateLotteryFootballGameZucaiSfcExists(String id) {
        if (lotteryFootballGameZucaiSfcMapper.selectById(id) == null) {
            throw exception(LOTTERY_FOOTBALL_GAME_ZUCAI_SFC_NOT_EXISTS);
        }
    }

    @Override
    public LotteryFootballGameZucaiSfcDO getLotteryFootballGameZucaiSfc(String id) {
        return lotteryFootballGameZucaiSfcMapper.selectById(id);
    }

    @Override
    public PageResult<LotteryFootballGameZucaiSfcDO> getLotteryFootballGameZucaiSfcPage(AppLotteryFootballGameZucaiSfcPageReqVO pageReqVO) {
        return lotteryFootballGameZucaiSfcMapper.selectPage(pageReqVO);
    }

}
